#!/usr/bin/env bash

help(){
    cat<<__EOF__
    usage: m update [ list | install | help ]


    Examples:
      m update list                                                 # list available updates
      m update install all                                          # install all the available updates
      m update install iTunesX-12.4.1 RAWCameraUpdate6.20-6.20      # install specific updates

__EOF__
}


install_updates(){
    # at least one package
    [ -z "$1" ] && help && exit 1
    case $1 in
        all)
            sudo softwareupdate --install --all
            ;;
        *)
            sudo softwareupdate --install "$@"
            ;;
    esac
}


case $1 in
    help)
        help
        ;;
    list|ls)
        sudo softwareupdate --list
        ;;
    install)
        shift
        install_updates "$@"
        ;;
    *)
        help
        ;;

esac
